//
//  LRXHelpMeModel.m
//  路人侠
//
//  Created by zhangxulong on 2/21/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXHelpMeInfoModel.h"


@implementation LRXHelpMeInfoModel
- (instancetype)initHelpModelWithDic:(NSDictionary *)responceObject
{
    if (self = [super init]) {
        
     
        //人物的获取
        if (![responceObject[@"user"] isEqual:[NSNull null]]) {
            LRXUserModel * user = [[LRXUserModel alloc]init];
            user.userName = responceObject[@"user"][@"username"];
            user.userImage = responceObject[@"user"][@"profile_url"];
            user.sexy = responceObject[@"user"][@"sexy"];
            self.userInfo = user;
            self.userIcon = responceObject[@"user"][@"profile_url"];
        }
       
        if (![responceObject[@"user_profile"] isEqual:[NSNull null]] && responceObject[@"user_profile"] != nil) {
            self.userIcon = responceObject[@"user_profile"];
            
        }
        
        //物品的获取
        //再一次解析content的数据
        CGFloat sumMoney = 0;
        if (![responceObject[@"content"] isEqual:[NSNull null]]) {
            
            NSMutableArray * thingArray = [NSMutableArray array];
            
            for (NSDictionary * thingDic in responceObject[@"content"])
            {
                LRXThing * thing = [LRXThing thingWith:thingDic];
                sumMoney += [thing.thingMoney floatValue] * [thing.thingCount floatValue];
                [thingArray addObject:thing];
            }
            self.thingArray = thingArray;
            self.allMoney = [NSString stringWithFormat:@"%.2f",sumMoney];
            self.tip = [NSString stringWithFormat:@"%.2f",sumMoney * 0.1];
        }
       

        if (![responceObject[@"location"] isEqual:[NSNull null]] && responceObject[@"location"][@"to_position"]) {
            self.buyAddr = responceObject[@"location"][@"to_position"];
        }
        if (![responceObject[@"location"] isEqual:[NSNull null]]  && responceObject[@"location"][@"back_position"])
        {
            self.sendAddr = responceObject[@"location"][@"back_position"];
        }
        self.back_position = responceObject[@"back_position"];
        
        if (![responceObject[@"order"] isEqual:[NSNull null]]) {
            self.orderModel = [LRXMyHelpOrderModel myHelpOrderMdel:responceObject[@"order"]];
        }
        
        
        
        //取值范围
        NSRange timeRange = {11,5};
        NSString * startTime = responceObject[@"req_start_time"];
        startTime = [startTime substringWithRange:timeRange];
        NSString * endTime = responceObject[@"req_end_time"];
        endTime = [endTime substringWithRange:timeRange];
        
        self.createTime = responceObject[@"created_at"];
        self.itemID = responceObject[@"id"];
        self.startTime = startTime;
        self.endTime = endTime;
        self.statue = [responceObject[@"status"] integerValue];
        
        self.is_home_delivery = responceObject[@"is_home_delivery"];
        self.remark = responceObject[@"remark"];
    }
    return self;
}
+ (instancetype)helpModelWithDic:(NSDictionary *)responeObject
{
    return [[LRXHelpMeInfoModel alloc]initHelpModelWithDic:responeObject];
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@--%@--%@",self.thingArray,self.userInfo,self.orderModel];
}
@end
